//
//  ViewController.swift
//  333333333
//
//  Created by wangyong的MAC on 2021/9/7.
//

import UIKit
class ViewController: UIViewController {
    var flag:FeatureFlags?
    override func viewDidLoad() {
        super.viewDidLoad()
        let jsonString = """
        {   "feature-search": false,"experiment-note-limit": 30
        }
        """
        if let data = jsonString.data(using: .utf8) {
            let decoder = JSONDecoder()
            if let flags = try? decoder.decode(FeatureFlags.self, from: data) {
                flag = flags
            }
        }
        let button = UIButton.init(type: UIButton.ButtonType.system)
        button.tintColor = UIColor.black
        button.setTitle("点击", for: UIControl.State.normal)
        button.frame = CGRect.init(x: 100, y: 100, width: 150, height: 100)
        self.view.addSubview(button)
        button.addTarget(self, action: #selector(goToFlagVC), for: .touchUpInside)
    }
    @objc func goToFlagVC() {
        
        let searchToggleVC = FlagToggleViewController(
            // 将封装器的实例传给了VC，这会使得VC可以更改封装器中属性的值
            flag: flag!.$isSearchEnabled
        )
        self.present(searchToggleVC, animated: true, completion:nil)
    }
}

